package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventChangeTypeBo;
import com.ruoyi.event.domain.vo.EventChangeTypeVo;
import com.ruoyi.event.service.IEventChangeTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 人员类型转换
 *
 * @author xiaohao
 * @date 2023-02-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/changeType")
public class EventChangeTypeController extends BaseController {

    private final IEventChangeTypeService iEventChangeTypeService;

    /**
     * 查询人员类型转换列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventChangeTypeVo> list(EventChangeTypeBo bo, PageQuery pageQuery) {
        return iEventChangeTypeService.queryPageList(bo, pageQuery);
    }

    @PostMapping("query")
    public R<List<EventChangeTypeVo>> query(@RequestBody EventChangeTypeBo bo) {
        return R.ok(iEventChangeTypeService.queryList(bo));
    }

    /**
     * 导出人员类型转换列表
     */
    @Log(title = "人员类型转换", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventChangeTypeBo bo, HttpServletResponse response) {
        List<EventChangeTypeVo> list = iEventChangeTypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员类型转换", EventChangeTypeVo.class, response);
    }

    /**
     * 获取人员类型转换详细信息
     *
     * @param typeId 主键
     */
    @GetMapping("/{typeId}")
    public R<EventChangeTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable Long typeId) {
        return R.ok(iEventChangeTypeService.queryById(typeId));
    }

    /**
     * 新增人员类型转换
     */
    @Log(title = "人员类型转换", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventChangeTypeBo bo) {
        return toAjax(iEventChangeTypeService.insertByBo(bo));
    }

    /**
     * 修改人员类型转换
     */
    @Log(title = "人员类型转换", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventChangeTypeBo bo) {
        return toAjax(iEventChangeTypeService.updateByBo(bo));
    }

    /**
     * 删除人员类型转换
     *
     * @param typeIds 主键串
     */
    @Log(title = "人员类型转换", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] typeIds) {
        return toAjax(iEventChangeTypeService.deleteWithValidByIds(Arrays.asList(typeIds), true));
    }
}
